package com.beans;

import java.io.IOException;
import java.io.Serializable;
import java.util.List;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;

import model.Movie;

import com.services.MoviesService;

@ManagedBean(name = "moviesBean")
@RequestScoped
public class MoviesBean implements Serializable {

	@EJB
	MoviesService service;

	@ManagedProperty(value = "#{movieBean}")
	private MovieBean movieBean;
	
	private List<Movie> movies;
	
	public MoviesBean() {

	}

	public MovieBean getMovieBean() {
		return movieBean;
	}

	public void setMovieBean(MovieBean movieBean) {
		this.movieBean = movieBean;
	}
	
	public List<Movie> getMovies() {
		this.movies = service.getAllMovies();
		return movies;
	}

	public void setMovies(List<Movie> movies) {
		this.movies = movies;
	}

	public void navigateToMoviePage(int movieId) throws IOException {
		this.movieBean.setMovie(service
				.getMovieById(movieId));
		
		FacesContext.getCurrentInstance().getExternalContext()
				.redirect("movie.seam");
	}
	
}
